<?php
class FileController extends ApiController
{
    public $login_require = array();
    public $self_error_list = array(
        'no_file' => array('errno' => 1135001, 'errmsg' => '无文件上传'),
        );
    public function actionUpload()
    {
        // upload start
        $file_cpt = new FilesComponent;
        $upload_result = $file_cpt->upload('file');
        if (!$upload_result) {
            if ($file_cpt->error == '无文件上传') {
                $this->status = $this->error_list['no_file'];
                return;
            } else {
                $this->status['errno']= 1135002;
                $this->status['errmsg']= $file_cpt->error;
                return;
            }
        } else {
            $this->status = $this->error_list['success'];
            $result['url'] = Yii::app()->request->hostInfo.'/download/'.$upload_result['hash'];
            if (in_array($upload_result['extension'], array('png','jpg','bmp','gif'))) {
                $result['url'] = Yii::app()->request->hostInfo.'/images/'.$upload_result['hash'].'.png';
            }
            $result['hash'] = $upload_result['hash'];
            $result['size'] = $upload_result['size'];
            $this->result = $result;
        }

    }
    
}
?>
